package com.chif.goingplus.controller;

import com.chif.goingplus.aop.log.LogNote;
import com.chif.goingplus.pojo.Order;
import com.chif.goingplus.pojo.Search;
import com.chif.goingplus.service.OrderService;
import com.chif.goingplus.utils.JsonUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@CrossOrigin
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;



    @RequestMapping("/add")
    public String addOrder(Order order){
        return orderService.addOrder(order)+"";
    }

    @RequestMapping("/delete")
    public String deleteOrderById(int id){
        orderService.deleteOrderById(id);
        return "删除订单信息成功";
    }

    @RequestMapping("/query")
    @LogNote(value = "测试接口日志")
    public String queryOrderById(int id){
        return JsonUtils.getJson(orderService.queryOrderById(id));
    }


    @RequestMapping("/update")
    public String updateOrder(Order order){
        System.out.println(order.toString());
        orderService.updateOrder(order);
        return "修改订单信息成功";
    }

    @RequestMapping("/queryAll")
    public String queryAllOrder(){
        return JsonUtils.getJson(orderService.queryAllOrder());
    }


    /**
     * 分页获取所有订单数据
     * @param currentPage
     * @return
     */
    @RequestMapping("/queryAllByPageHelper")
    public String queryAllByPageHelper(int currentPage,int pageSize){
        return JsonUtils.getJson(orderService.pageHelperOrder(currentPage,pageSize));
    }


    /**
     * 查询所有售票员的订单数量
     * @return
     */
    @RequestMapping("/querySellerOrder")
    public String querySellerOrder(){
        return JsonUtils.getJson(orderService.querySellerOrder());
    }


    /**
     * 获取总销售额和周同比，日同比,日销售额
     */
    @RequestMapping("/querySaleCount")
    public String querySaleCount(){
        return JsonUtils.getJson(orderService.getSaleCount());
    }

    /**
     * 获取支付笔数和周同比，日同比,日销售额
     */
    @RequestMapping("/queryPayCount")
    public String queryPayCount(){
        return JsonUtils.getJson(orderService.getPayCount());
    }


    /**
     * 搜索
     */
    @RequestMapping("/search")
    public String searchOrder(Search search){
        return JsonUtils.getJson(orderService.searchOrder(search));
    }

    /**
     * 获取预测 1.当天客流量数据2.月客流量预测
     */
    @RequestMapping("/forecast")
    public String getForecastCount(){
        return JsonUtils.getJson(orderService.getDayForecast());
    }
}
